import { getUserInfo } from '@/api'
import { LOGIN_TOKEN, USER_INFO } from '@/store/actionTypes'
import { clearToken } from '@/utils'

export function infoAction () {
  return async dispatch => {
    const res = await getUserInfo()
    dispatch({
      type: USER_INFO,
      payload: res.data
    })
  }
}

export function logoutAction () {
  return dispatch => {
    clearToken()
    dispatch({
      type: LOGIN_TOKEN,
      payload: ''
    })
    dispatch({
      type: USER_INFO,
      payload: {}
    })
  }
}
